import request from '@/router/axios';
import {baseUrl} from '@/config/env';
import website from "@/config/website";

export const loginByUsername = (tenantId, account, password, type, key, code) => request({
  url: baseUrl +'/api-uaa/oauth/token',
  method: 'post',
  params: {
    grant_type: (website.captchaMode ? "password_code" : "password"),
    tenantId: tenantId,
    username: account,
    password: password,
    deviceId: key,
    validCode: code,
  }
});

export const loginBySocial = (tenantId, source, code, state) => request({
  url: '/api/blade-auth/token',
  method: 'post',
  headers: {
    'Tenant-Id': tenantId
  },
  params: {
    tenantId,
    source,
    code,
    state,
    grantType: "social",
    scope: "all",
  }
});


export const getUserInfo = () => request({
  url: baseUrl + '/user/getUserInfo',
  method: 'get'
});
export const getCurrentUserInfo = () => request({
  url: baseUrl + '/api-user/users/current',
  method: 'get'
});

export const refreshToken = (refreshToken, tenantId) => request({
  // url: baseUrl + '/api-uaa/oauth/token?grant_type=refresh_token&refresh_token='+refrshToken,
  url: baseUrl + '/api-uaa/oauth/token',
  method: 'post',
  params: {
    grant_type: "refresh_token",
    refresh_token: refreshToken,
    tenantId: tenantId
  }
})

export const renewToken = (refreshToken, tenantId) => request({
  // url: baseUrl + '/api-uaa/oauth/token?grant_type=refresh_token&refresh_token='+refrshToken,
  url: baseUrl + '/api-uaa/tokens/renew',
  method: 'get',
})

export const registerGuest = (form, oauthId) => request({
  url: '/api/blade-user/register-guest',
  method: 'post',
  params: {
    tenantId: form.tenantId,
    name: form.name,
    account: form.account,
    password: form.password,
    oauthId
  }
});

export const getButtons = () => request({
  url: baseUrl + '/api-user/menus/buttons',
  method: 'get'
});
export const getMenu = () => request({
  url: baseUrl + '/api-user/menus/routes',
  method: 'get'
});

export const getTopMenu = (topId) => request({
  // url: baseUrl + '/api-user/menus/findAlls',
  // url: baseUrl + '/api-user/topmenu/getMenuByTopId',
  url: baseUrl + '/api-user/topmenu/list',
  method: 'get',
  params: {
    topId
  }
});
export const getTopMenuById = (topId) => request({
  // url: baseUrl + '/api-user/menus/findAlls',
  // url: baseUrl + '/api-user/topmenu/getMenuByTopId',
  url: baseUrl + '/api-user/topmenu/getTopMenuById',
  method: 'get',
  params: {
    id: topId
  }
});
export const getCaptcha = () => request({
  // url: '/api/blade-auth/captcha',
  url: baseUrl + '/api-uaa/validata/code',
  method: 'get'
});



export const sendLogs = (list) => request({
  url: baseUrl + '/user/logout',
  method: 'post',
  data: list
})

export const logout = () => request({
  url: baseUrl + '/api-uaa/oauth/remove/token',
  method: 'get'
})
